package com.kuaimacode.kframework.admin.config.freemaker;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import java.util.Map;

@Component
public class MyCommandLineRunner {
    /**
     * 增加自定义视图变量和方法
     *
     * @return
     */
    @Bean
    public CommandLineRunner customFreemarker(FreeMarkerViewResolver resolver) {
        return new CommandLineRunner() {
            @Override
            public void run(String... strings) {
                //增加视图
                resolver.setViewClass(MyFreemarkerView.class);
                //添加自定义解析器
                Map map = resolver.getAttributesMap();
                map.put("convert", new ConvertTemplate());
                map.put("getDict", new DictTemplate());
            }
        };
    }
}
